<?php

// -----------------------------------------------------------------------------

include "config/config.php";
include "DBManager.php";
include "createDBIfNotExists.php";

$db = new DBManager($dbPath);

// -----------------------------------------------------------------------------

if (!isset($_POST['dateCreate']) || !isset($_POST['content']) || !isset($_POST['from'])) {

    exit("需要传入有效的参数。");

}

$from = $_POST['from'];
$dateCreate = $_POST['dateCreate'];
$content = $_POST['content'];

?>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <title>保存成功</title>
    <link rel="stylesheet" href="resources/bootstrap-4.3.1-dist/css/bootstrap.min.css">
</head>
<body>

<!-- ----------------------------------------------------------------------- -->

<?php include 'global/globalNavBar.php'; ?>

<!-- ----------------------------------------------------------------------- -->

<!--container-->
<div class="container mt-2">

    <?php
        try {
            if ($from == "edit") {
                $db->writeToTable($dateCreate, $content);
            } else {
                $db->appendContent($dateCreate, $content);
            }
            echo "保存成功！";
        } catch (Exception $e) {
            echo $e->getMessage();
        }
    ?>

</div>

<!-- ----------------------------------------------------------------------- -->
<script src="resources/jquery/jquery-3.4.0.min.js"></script>
<script src="resources/bootstrap-4.3.1-dist/js/bootstrap.min.js"></script>
<!-- ----------------------------------------------------------------------- -->

</body>
</html>
